

namespace NodeBasedSkillEditor.Model.Node.RT
{
    public class Node_Multiply_RT : RT_Node
    {
        public RT_SingleValuePort[] Factor_RT;

        public RT_SingleValuePort Result_RT;

        public Node_Multiply_RT(Node_Multiply sourceData, RT_DAG parentDag) : base(sourceData, parentDag)
        {
            Factor_RT = BuildRTPortArrayFromGroup<RT_SingleValuePort>(EPortIOType.Input, sourceData.Factor);

            Result_RT = new RT_SingleValuePort(EPortIOType.Output, sourceData.Result, this);
            Result_RT.OnGetValue = GetResult;

        }

        public AValue GetResult(DAG_Executor executor)
        {
            Result_RT.SourceValue.Reset();
            if (Factor_RT.Length > 0)
            {
                var firstValue = Factor_RT[0].GetValue(executor);
                Result_RT.SourceValue.Assign(firstValue);

                for (int i = 1; i < Factor_RT.Length; i++)
                {
                    var currValue = Factor_RT[i].GetValue(executor);
                    Result_RT.SourceValue.Multiply(currValue);
                }
            }
            return Result_RT.SourceValue;
        }
    }
}